<%@ page contentType="text/html; charset=utf-8"%>

<div id="gradeSettingDiv" style="width: 100%;display: none;">

	<div class="infoDiv">
		<div class="infoHead">
			<h3 style="margin-top: 5px; margin-left: 10px;">评分配置</h3>
		</div>
		<div style="margin-top: 20px;margin-left: 20px;">
			评分时小于最小阀值按100分计算，处于最小和最大阀值之间的根据比例取0-100之间的分数，而大于最大阀值按0分计算
		</div>

		<div style="height: 50px;">
		
			 	<input type="button" onclick="addGradeConfigView()" style="width: 100px;float: right;" class="btn btn-primary m_r" value="添加条目"></input>
		</div>
		<div id="gradeConfigTableDiv" >
			<table class="table table-striped table-bordered" id="gradeConfigTable"></table>
			<table class="table table-striped table-bordered" id="aadGradeConfigTable"></table>
		</div>

	</div>
</div>
<script>

	var gradeConfigData;

		$(function() {
			gradeConfigDatas();
		});


		function gradeConfigDatas(){
			
			$.post("gradeConfig", {"actionType":"getConfigs"},
					   function(data){
						
							
				
						gradeConfigData = data;
							setGradeConfigTableData();
					
					   },"json");
			
			
		}


		function setGradeConfigTableData(data){
			
			var tableVal = "";
			
			
			for(var i=0;i<gradeConfigData.length;i++){
				var obj = gradeConfigData[i];
			
				
				if(i>=4){
					tableVal = tableVal+"<tr><td style='width:230px;'><span>名称：</span><input id='"+obj.id+"_name' value='"+obj.name+"' type='text'></td><td><span>最小值：</span>"+
					"<input id='"+obj.id+"_minNumber' value='"+obj.minSpeed+"'  type='text'><span>（KB/s / % / ms）</span></td>"+
					"<td><span>最大值：</span><input id='"+obj.id+"_maxNumber' value='"+obj.maxSpeed+"'  type='text'><span>（KB/s / % / ms）</span></td><td>"+
					"<a onclick='updateGradeConfig("+obj.id+")' href='#'>修改信息</a><a href='#' onclick='delGradeConfig("
							+obj.id+")' style='margin-left: 20px;'>删除账号</a></td></tr>";
				}else{
					
					tableVal = tableVal+"<tr><td style='width:230px;'><span>名称：</span><input id='"+obj.id+"_name' value='"+obj.name+"' disabled type='text'></td><td><span>最小值：</span>"+
					"<input id='"+obj.id+"_minNumber' value='"+obj.minSpeed+"'  type='text'><span>（KB/s / % / ms）</span></td>"+
					"<td><span>最大值：</span><input id='"+obj.id+"_maxNumber' value='"+obj.maxSpeed+"'  type='text'><span>（KB/s / % / ms）</span></td><td>"+
					"<a onclick='updateGradeConfig("+obj.id+")' href='#'>修改信息</a>"+
							"</td></tr>";
					
				}
				
			
			}

			$("#gradeConfigTable").html(tableVal);
			
			
		}
		
		function addGradeConfigView(){

			
			
			var id = new Date().getTime();
			
			var trStr = "<tr ><td style='width:230px;'><span >名称：</span><input id='"+id+"_name'  type='text'/></td><td><span>最小值：</span><input id='"+id+"_minNumber'  type='text'><span>（KB/s / % / ms）</span></td>"+
			"<td><span>最大值：</span><input id='"+id+"_maxNumber'  type='text'><span>（KB/s / % / ms）</span></td><td><a onclick='addGradeConfig("+id+")' href='#'>保存信息</a><a href='#'"+
			" onclick='closeAddGradeConfig()'  style='margin-left: 20px;'>取消添加</a></td></tr>";
			
			$("#aadGradeConfigTable").html(trStr);
			
			
			
		}
		
		
		function closeAddGradeConfig(){
			
			 $("#aadGradeConfigTable").html("");
			
		}
		
		function addGradeConfig(id){
			
		 var name =	$("#"+id+"_name").val();
		 var minNumber = $("#"+id+"_minNumber").val();
		 var maxNumber = $("#"+id+"_maxNumber").val();
		 
	
		 if(name!=null&&name!=""&&minNumber!=null&&minNumber!=""&&maxNumber!=null&&maxNumber!=""){
			 
			 $.post("gradeConfig", {"actionType":"addConfig","name":name,"maxNumber":maxNumber,"minNumber":minNumber,"id":id},
					   function(data){
						
				
					 if(true==data){
						 
						 gradeConfigDatas();
						 
						 closeAddGradeConfig();
					 }else{
						 
						 alert(data);
					 }
					 
					   },"json");
			 
		 }else{
			 
			 alert("不能保存空的内容");
			 
		 }
		 
		 
		
		 
		
			 
		}
		
		function updateGradeConfig(id){
			
			 var name =	$("#"+id+"_name").val();
			 var minNumber = $("#"+id+"_minNumber").val();
			 var maxNumber = $("#"+id+"_maxNumber").val();
			 
		

			 
			 if(name!=null&&name!=""&&minNumber!=null&&minNumber!=""&&maxNumber!=null&&maxNumber!=""){
				 
				 $.post("gradeConfig", {"actionType":"updateConfig","name":name,"maxNumber":maxNumber,"minNumber":minNumber,"id":id},
						   function(data){
							
						
				
						 if(true==data){
							 
							 gradeConfigDatas();
							 
							alert("修改成功");
						 }else{
							 alert(data.msg);
							 
						 }
						 
						   },"json");
				 
			 }else{
				 
				 alert("不能保存空的内容");
				 
			 }
			 
		}
		
		function delGradeConfig(id){
			
			 $.post("gradeConfig", {"actionType":"delConfig","id":id},
					   function(data){
						
				
					 if(true==data){
						 
						 gradeConfigDatas();
						 
						alert("删除成功成功");
					 }else{
						 
						 alert("删除失败");
					 }
					 
				 },"json");
			
		}

</script>